package AS3 {
import AS3.Country;

import mx.collections.*;
import mx.controls.Alert;
import mx.core.Application;
import mx.core.FlexGlobals;

import zakladki.PlotPanel;

public class MainCalculator {

    private var bookmarkCalculator:BookmarkCalculator;
    private var coefficientCalculator:CoefficientCalculator;

    private var chosenCountry:Country;

    private var mainApp:Fossilminator = FlexGlobals.topLevelApplication as Fossilminator;

    public function calculateClick(chosenCountry:Country, emissions:CountryEmission,person:Person ):CountryEmission {
        try {
            this.chosenCountry = chosenCountry;

            var coefficientParams:CalculationParams = coefficientCalculator.createCoefficientParams(chosenCountry);
            coefficientParams.nonStatisticMode = true;
            coefficientParams.units = new String("M");

            var calcResult:CalculationResult = bookmarkCalculator.calculate(chosenCountry, person, coefficientParams);


            emissions.general = calcResult.general;
            emissions.deforestation = calcResult.constructionMaintenance;
            emissions.electricity = calcResult.electricity;
            emissions.consumption = calcResult.consumption;
            emissions.food = calcResult.food;
            emissions.flights = calcResult.airTransport;
            emissions.publicTransport = calcResult.publicTransport;
            emissions.carProduction = calcResult.carProduction;
            emissions.fuelBurnings = calcResult.fuelBurnings;
            emissions.airCondition = calcResult.airConditioning;
            emissions.warmWater = calcResult.hotWater;
            emissions.heating = calcResult.heating;
            emissions.maintenance = calcResult.constructionMaintenance;


        } catch(e:Error) {
            Alert.show("calculate click error: " + e.message);
        }

        return emissions;
    }


    public function setBookMarkCalculator(bookMarkCalc:BookmarkCalculator):void {
        this.bookmarkCalculator = bookMarkCalc;
    }

    public function setCoeficientCalculator(calcCodeOther:CoefficientCalculator):void {
        this.coefficientCalculator = calcCodeOther;
    }










}

}



